#include "..\deleaker\mem2.h"
#include "book.h"

#include "..\\include\cfg_items.h"
#include "conf_loader.h"
#include "config_data.h"

extern void elf_exit(void);

////k800_r8bf003_EU
//DISP_OBJ* (*Dispobj_Create)(DISP_OBJ*,void(*DispDescCreate)(DISP_DESC*))=(DISP_OBJ* (*)(DISP_OBJ*,void(*DispDescCreate)(DISP_DESC*)))0x45459595;
//void (*Dispobj_Destroy)(DISP_OBJ*)=(void (*)(DISP_OBJ*))0x45459629;
//void (*DispObject_SetTitleType)(DISP_OBJ*,int type)=(void (*)(DISP_OBJ*,int type))0x45458E3D;
//void (*DispObject_SetStyle)(DISP_OBJ*,int style)=(void (*)(DISP_OBJ*,int type))0x4545C361;
//
////W660_EU_r8bb001
//DISP_OBJ* (*Dispobj_Create)(DISP_OBJ*,void(*DispDescCreate)(DISP_DESC*))=(DISP_OBJ* (*)(DISP_OBJ*,void(*DispDescCreate)(DISP_DESC*)))0x4548112D;
//void (*Dispobj_Destroy)(DISP_OBJ*)=(void (*)(DISP_OBJ*))0x454811C1;
//void (*DispObject_SetTitleType)(DISP_OBJ*,int type)=(void (*)(DISP_OBJ*,int type))0x454809BD;
//void (*DispObject_SetStyle)(DISP_OBJ*,int style)=(void (*)(DISP_OBJ*,int type))0x45483F51;

//W660_HK
//DISP_OBJ* (*Dispobj_Create)(DISP_OBJ*,void(*DispDescCreate)(DISP_DESC*))=(DISP_OBJ* (*)(DISP_OBJ*,void(*DispDescCreate)(DISP_DESC*)))0x454909ED;
//void (*Dispobj_Destroy)(DISP_OBJ*)=(void (*)(DISP_OBJ*))0x45490A81;
//void (*DispObject_SetTitleType)(DISP_OBJ*,int type)=(void (*)(DISP_OBJ*,int type))0x4549026D;
//void (*DispObject_SetStyle)(DISP_OBJ*,int style)=(void (*)(DISP_OBJ*,int type))0x45493811;

//W800
DISP_OBJ* (*Dispobj_Create)(DISP_OBJ*,void(*DispDescCreate)(DISP_DESC*))=(DISP_OBJ* (*)(DISP_OBJ*,void(*DispDescCreate)(DISP_DESC*)))0x44E896F5;
void (*Dispobj_Destroy)(DISP_OBJ*)=(void (*)(DISP_OBJ*))0x44E8978D;
void (*DispObject_SetTitleType)(DISP_OBJ*,int type)=(void (*)(DISP_OBJ*,int type))0x44E8BFCD;
void (*DispObject_SetStyle)(DISP_OBJ*,int style)=(void (*)(DISP_OBJ*,int type))0x44E8D375;


int CMyBook::TerminateElf(CBook ** pbookmanbook, CMyBook* book)
{
  book->Free();
  return 1;
}

int CMyBook::ShowAuthorInfo(CBook ** pbookmanbook, CMyBook* book)
{
  MSG(STR_ABOUT,*pbookmanbook);
  return 1;
}

int CMyBook::ReconfigElf(CBook ** pbookmanbook, CMyBook* book)
{
  RECONFIG_EVENT_DATA *reconf=(RECONFIG_EVENT_DATA *)pbookmanbook;
  int result=0;
  if (wstrcmpi(reconf->path,successed_config_path)==0 && wstrcmpi(reconf->name,successed_config_name)==0)
  {
    InitConfig();
    result=1;
  }
  return(result);
}


const PAGE_MSG base_page_PAGE_MSG[]@ "DYN_PAGE"={
  DECLARE_PAGE_DESC_MSG( ELF_TERMINATE_EVENT, CMyBook::TerminateElf )
  DECLARE_PAGE_DESC_MSG( ELF_SHOW_INFO_EVENT, CMyBook::ShowAuthorInfo )
  DECLARE_PAGE_DESC_MSG( ELF_RECONFIG_EVENT, CMyBook::ReconfigElf )
  NIL_EVENT_TAG,NULL
};

const PAGE_DESC CMyBook::base_page = {"MyBook_BasePage",0,base_page_PAGE_MSG};


CMyBook::CMyBook() :CBook("Standby_Widget",&base_page)
{
  InitConfig();
  //DISP_OBJ* disp_standby = GUIObject_GetDispObject((GUI*)List_Get(Display_GetTopBook(0)->xguilist->guilist,0));  // narysuje na aktualnie widocznym booku 
  DISP_OBJ* disp_standby = GUIObject_GetDispObject(SBY_GetStatusIndication(Find_StandbyBook()));     // narysuje na standby
  disp_widget = Dispobj_Create(disp_standby,(void(*)(DISP_DESC*))CMyDisp::DispDescCreate);
  DispObject_SetTitleType(disp_widget,title_t);//UI_TitleMode_None  
  DispObject_SetStyle(disp_widget,style_t);//UI_OverlayStyle_TrueFullScreen
  DispObject_Show(disp_widget,1);
  DispObject_SetTitleText(disp_widget,STR("Electric0Metr \n(c) zylka"));
}

CMyBook::~CMyBook()
{
  if(disp_widget) Dispobj_Destroy(disp_widget);
  elf_exit();
}

